package com.hellogood.yaohuo.client;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.PasswordItem;
import com.smartgwt.client.widgets.form.fields.TextItem;
import com.smartgwt.client.widgets.form.fields.events.KeyPressEvent;
import com.smartgwt.client.widgets.form.fields.events.KeyPressHandler;
import com.smartgwt.client.widgets.layout.HLayout;
import com.smartgwt.client.widgets.layout.VLayout;

public class LoginPanel extends VLayout {
	private DynamicForm loginForm = null;
	private TextItem userNameItem = null;
	private PasswordItem passwordItem = null;
	private ButtonItem loginBtn = null;

	public LoginPanel() {
		setWidth100();
		setHeight100();
		setBackgroundColor("white");
		HLayout layout1 = new HLayout();
		layout1.setWidth("60%");
		layout1.setHeight(20);
		addMember(layout1);

		HLayout topLayout = new HLayout();
		topLayout.setWidth100();
		topLayout.setHeight(50);

		addMember(topLayout);

		addMember(layout1);

		HLayout middleLayout = new HLayout();
		middleLayout.setSize("100%", "100%");

		userNameItem = new TextItem("usernameItem", "用户名");
		userNameItem.addKeyPressHandler(new KeyPressHandler() {

			@Override
			public void onKeyPress(KeyPressEvent event) {
				if (event.getKeyName() != null && event.getKeyName().equals("Enter")) {
					passwordItem.focusInItem();
				}
			}
		});
		passwordItem = new PasswordItem("passwordItem", "密码");
		passwordItem.addKeyPressHandler(new KeyPressHandler() {

			@Override
			public void onKeyPress(KeyPressEvent event) {
				if (event.getKeyName() != null && event.getKeyName().equals("Enter")) {
					loginBtn.focusInItem();
				}
			}
		});
		loginBtn = new ButtonItem("loginItem", "登录");
		loginBtn.setWidth(50);
		loginBtn.setHeight(25);

		loginForm = new DynamicForm();
		loginForm.setFields(userNameItem, passwordItem, loginBtn);
		loginForm.setShowEdges(true);
		loginForm.setMargin(50);
		loginForm.setCellPadding(10);
		loginForm.setWidth(400);
		loginForm.setHeight(200);
		loginForm.setBackgroundColor("E4ECF9");
		loginBtn.setAlign(Alignment.RIGHT);

		HLayout layout2 = new HLayout();
		layout2.setWidth("10%");
		HLayout layout3 = new HLayout();
		layout3.setWidth("10%");

		middleLayout.setMembers(layout2, loginForm, layout3);
		addMember(middleLayout);
	}

	public TextItem getUserNameItem() {
		return userNameItem;
	}

	public PasswordItem getPasswordItem() {
		return passwordItem;
	}

	public ButtonItem getLoginBtn() {
		return loginBtn;
	}

	public DynamicForm getForm() {
		return loginForm;
	}
}
